#include "stdafx.h"
#include "Pushers.h"
#include <Utilities\glext.h>
#include <Utilities\Extensions.h>

PushAttribute::PushAttribute(GLbitfield mask)
{
	glPushAttrib(mask);
}

PushAttribute::~PushAttribute(void)
{
	glPopAttrib();
}

PushMatrix::PushMatrix(GLenum mode)
{
	glMatrixMode(mode);
	glPushMatrix();
}

PushMatrix::~PushMatrix(void)
{
	glPopMatrix();
}

PushDrawCall::PushDrawCall(GLenum mode)
{
	glBegin(mode);
}

PushDrawCall::~PushDrawCall(void)
{
	glEnd();
}

PushQuery::PushQuery(GLuint id)
{
	glBeginQuery(GL_SAMPLES_PASSED, id);
}

PushQuery::~PushQuery(void)
{
	glEndQuery(GL_SAMPLES_PASSED);
}

PushShader::PushShader(const Shader& shader)
:_shader(shader)
{
	_shader.Enable();
}

PushShader::~PushShader(void)
{
	_shader.Enable(false);
}

PushFBOAttachment::PushFBOAttachment(FramebufferObject& FBO, const GLenum attachment)
:_FBO(FBO), _attachment(attachment)
{ }

PushFBOAttachment::PushFBOAttachment(FramebufferObject& FBO, const GLenum attachment, const Texture& texture)
:_FBO(FBO), _attachment(attachment)
{
	_FBO.AttachTexture(_attachment, texture.GetTarget(), texture.GetReadId());
}

PushFBOAttachment::PushFBOAttachment(FramebufferObject& FBO, const GLenum attachment, const Texture& texture, const int layer)
:_FBO(FBO), _attachment(attachment)
{
	_FBO.AttachTexture(_attachment, texture.GetTarget(), texture.GetReadId(), 0, layer);
}

PushFBOAttachment::PushFBOAttachment(FramebufferObject& FBO, const GLenum attachment, const RenderbufferObject& RBO)
:_FBO(FBO), _attachment(attachment)
{
	_FBO.AttachRenderBuffer(attachment, RBO.GetId());
}

PushFBOAttachment::~PushFBOAttachment(void)
{
	_FBO.Unattach(_attachment);
}

PushFBOAttachment2DRW::PushFBOAttachment2DRW(FramebufferObject& FBO, const GLenum attachment, const Texture2DRW& texture)
:PushFBOAttachment(FBO, attachment)
{
	_FBO.AttachTexture(_attachment, texture.GetTarget(), texture.GetWriteId());
}

PushFBOAttachment2DRW::~PushFBOAttachment2DRW(void)
{
	_FBO.Unattach(_attachment);
}

PushFBOAttachmentRectRW::PushFBOAttachmentRectRW(FramebufferObject& FBO, const GLenum attachment, const TextureRectRW& texture)
:PushFBOAttachment(FBO, attachment)
{
	_FBO.AttachTexture(_attachment, texture.GetTarget(), texture.GetWriteId());
}

PushFBOAttachmentRectRW::~PushFBOAttachmentRectRW(void)
{
	_FBO.Unattach(_attachment);
}

